#!/bin/bash
# Program:
#   filter some strings in the txt file 
# History:
# 2019/11/19	Qiu Chao First release

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
export PATH

imgFolder=
beginNum=
endNum=
dbgEn=

if [ -n "$1" ]; then
  imgFolder=$1
  if [ -n "$2" ]; then 
    beginNum=$2
  else
    echo -e "\033[40;32m Error you must input 2nd parameter as begin num------------------\033[0m" 
  fi
  if [ -n "$3" ]; then 
    endNum=$3
  else
    echo -e "\033[40;32m Error you must input 3rd parameter as end num--------------------\033[0m" 
  fi
  if [ -n "$4" ]; then 
    dbgEn=$4
    echo -e "\033[40;32m Info you input 4th parameter as jump the crc err and head err or rename fileName----\033[0m" 
  fi
else
  echo -e "\033[40;32m Geometry must be 1920x1080------------------\033[0m" 
  echo -e "\033[40;32m Function:Convert the images to folder--------------------------------------\033[0m" 
  echo -e "\033[40;32m ForExample::If you want convert l0809 folder-------------------------------\033[0m"
  echo -e "\033[40;32m ForExample::There ara tst3.jpg,tst4.jpg,tst5.jpg in the folder-------------\033[0m"
  echo -e "\033[40;32m ForExample::ForExample::You can use the commond: run ./l0809  3 5----------\033[0m"
  
  read -p "Please input your folder to convert: " imgFolder 
  read -p "Please input your number of begin: " beginNum
  read -p "Please input your number of end: " endNum
  read -p "Please input your dbgEn mode: " dbgEn 
fi 

prj_ocr_old_fait187.exe ${imgFolder}/tst ${beginNum} ${endNum} ${dbgEn}
rm -rf txt
mkdir txt
cp -rf ${imgFolder}/*.txt  ./txt
cd ./txt
utarback example 

## resUtar=`cat tmp.log`
## 
## echo "nidaye=${resUtar}"
## 
## if [[ $resUtar =~ "decompression OK" ]]; then
##   echo -e "\033[40;32m --Successully-\033[0m"
## else
##   echo -e "\033[40;31m --Sorry Failed --\033[0m"
## fi

## for (( i=${begin_num};i<${end_num};i=i+1))
## do
##   postfix=$(echo ${i} | awk '{printf("%05d\n",$0)}')
##   touch ts${postfix}
##   echo -e "\033[40;32m the created file is ts${postfix} -----------------------------\033[0m" 
## done

echo -e "\033[40;32m Finished it. -----------------------------\033[0m" 
